//
//  HGMusicTwoCollectionViewCell.m
//  悦享
//
//  Created by dllo on 16/3/21.
//  Copyright © 2016年 张洪国. All rights reserved.
//

#import "HGMusicTwoCollectionViewCell.h"
#import <UIImageView+WebCache.h>
#import "SongModel.h"
#import "SongMVModel.h"
@implementation HGMusicTwoCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews{
    
    self.label1 = [[UILabel alloc] init];
    [self.contentView addSubview:_label1];
    
    self.imageView1 = [[UIImageView alloc] init];
    [self.contentView addSubview:_imageView1];
    
    self.musicName = [[UILabel alloc] init];
    [self.contentView addSubview:_musicName];
    
    self.auNameLabel =[[UILabel alloc] init];
    [self.contentView addSubview:_auNameLabel];
    
    
    
    self.SQButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_SQButton];
    
    self.likeImage = [[UIImageView alloc] init];
    [self.contentView addSubview:_likeImage];
    
    self.likeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_likeLabel];
    
    self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_playButton];
}


   
- (void)setModel:(SongModel *)model{
    _model = model;
    [_imageView1 sd_setImageWithURL:[NSURL URLWithString:_model.picUrl] placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
    _musicName.text = _model.name;
    _auNameLabel.text = _model.singerName;
    _likeImage.image = [UIImage imageNamed:@"iconfont-xin.png"];
    
    NSString *str = [_model.favorites stringValue];
    _likeLabel.text = [NSString stringWithFormat:@"%@ 人", str];
    
    [_SQButton setImage:[UIImage imageNamed:@"iconfont-sq.png"] forState:UIControlStateNormal];
    
    //用新建model属性判断是否需要创建mvbutton
    if (_model.haveMV == YES) {
        self.mvButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:_mvButton];
        [_mvButton setImage:[UIImage imageNamed:@"iconfont-mv.png"] forState:UIControlStateNormal];
        _mvButton.frame = CGRectMake(230, 2, 40, 30);
        [_mvButton addTarget:self action:@selector(mvButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    
    
    [_playButton setImage:[UIImage imageNamed:@"iconfont-bofang-2.png"] forState:UIControlStateNormal];
    
    
}




- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    
    _label1.frame = CGRectMake(10, 5, 20, 30);
  
    
    _imageView1.frame = CGRectMake(35, 2, 40, 50);
  
    
    _musicName.frame = CGRectMake(90, 4, 120, 20);
    _musicName.font = [UIFont systemFontOfSize:15];
    
    _auNameLabel.frame = CGRectMake(90, 30, 50, 20);
   
    _auNameLabel.font = [UIFont systemFontOfSize:12];
    
    _likeImage.frame = CGRectMake(175, 30, 20, 20);
    
    
    _likeLabel.frame = CGRectMake(200, 30, 60, 20);
    
    _likeLabel.font = [UIFont systemFontOfSize:10];
    
    _SQButton.frame = CGRectMake(190, 2, 40, 30);
   
    
    
    
    
    _playButton.frame = CGRectMake(SREEN_WIDTH - 50, 10, 30, 30);
}
/**
 *  mvbutton点击方法
 *
 *  @param button
 */
- (void)mvButtonAction:(UIButton *)button{
    
    SongMVModel *mvModel = [_model.mvListArr lastObject];
    
    
    //通知传值跳到mvcontroller
    [[NSNotificationCenter defaultCenter] postNotificationName:@"mvPostToVC" object:mvModel];
    
}



@end
